/* `this processor work only on Chrome 
//encodeURIComponent
//decodeURIComponent

Ajax post example:
%%%%%%%%%%%%%%%%%%
$(selector).post(URL,data,function(data,status,xhr),dataType)
$("button").click(function(){
	$.post("demo_test_post.asp", {
	  name:"Donald Duck",
	  city:"Duckburg"
	}, function(data,status){
		alert("Data: " + data + "\nStatus: " + status);
	});
});

debug:
1. Remove (VOV) -
2. Remove alert visual tab
*/

////eva.vn kenh14.vn ione.net
////Feed list
var FL = [
////Group Name          Feeds (separate by comma)
// 'kenh14',				'http://kenh14.vn/musik.chn',
// 'eva',					'http://www.eva.vn/eva-sanh-dieu-c173.html',
// 'ione',					'http://ione.vnexpress.net/tin-tuc/thoi-trang/bi-kip-dep.html',
// 'dantri',				'http://dantri.com.vn/c20/xa-hoi.htm',
// 'VOV',					'http://vov.vn/Xa-hoi/314.vov',
// 'news.zing.vn',         'http://news.zing.vn/the-gioi-sao/sao-viet.html',
// 'bongdaplus',           'http://bongdaplus.vn/Hang-Nhat-QG/8.bbd',/* `not allow */
// 'gamethu',              'http://gamethu.vnexpress.net/gt/diem-tin/',
// 'sohoa.vnexpress.net',  'http://sohoa.vnexpress.net/tin-tuc/doi-song-so/giai-tri',
// 'tuoitre.vn',           'http://tuoitre.vn/Chinh-tri-Xa-hoi/Phap-luat/Index.html',
// '2sao',                 'http://2sao.vn/p0c1000/sao.vnn',
// 'Ngoi sao',             'http://ngoisao.net/tin-tuc/hau-truong/',
// 'vietnamnet',           'http://vietnamnet.vn/vn/xa-hoi/',
// 'vtc',                  'http://vtc.vn/2-0/xa-hoi/index.htm',	/* `not allow */
// '24h',                  'http://hcm.24h.com.vn/bong-da-c48.html',
/*
Add new file from: Nov 04, 2012
'dothi', 'http://dothi.net/cam-nang',
'kientrucnhadep', 'http://kientrucnhadep.batdongsan.com.vn/',
'archi', 'http://archi.vn/khong-gian-dep.html',

'tinmoi',	'http://www.tinmoi.vn/C/Khoa-hoc-tu-nhien',
'vntimes',	'http://vntimes.com.vn/khoa-hoc-cong-nghe/nganh-khoa-hoc-khac/',

'baodatviet','http://khoahoc.baodatviet.vn/home/KHCN/thegioiquanhta.datviet'
'tiin',	'http://tiin.vn/vui/chuyen-la.html',
*/

'Kỳ quặc',	'http://kenh14.vn/la.chn',
'Kỳ quặc',	'http://dantri.com.vn/chuyen-la.htm',
/*'Kỳ quặc',	'http://ione.vnexpress.net/tin-tuc/vui-la/anh.html',*/

'Khoa học',	'http://vnexpress.net/gl/khoa-hoc/',
'Khoa học',	'http://kenh14.vn/kham-pha.chn',
'Khoa học',	'http://kienthuc.net.vn/kham-pha/',
'Khoa học',	'http://kienthuc.net.vn/quan-su/',

'Kiến trúc', 'http://dothi.net/cam-nang',
'Kiến trúc', 'http://archi.vn/khong-gian-dep.html',
'Kiến trúc', 'http://archi.vn/tu-lam-dep-nha.html',
'Kiến trúc', 'http://archi.vn/du-lich-kien-truc.html',
'Kiến trúc', 'http://www.eva.vn/nha-dep-c169.html',
/*
http://batdongsan.com.vn: refer+pedding
http://ndhmoney.vn/web/guest/tieu-dung/khong-gian: pendding
http://nhadep.vnexpress.net/GL/Nha-dep/: refer+pendding
http://kienviet.net:pendding
*/
];


/* `If title contain words in this list, reject click */
var Not_Fetch = [
'vietnamnet', 'Thời sự tuần qua:,Thế giới 24h:',
'24h.com.vn', 'TRỰC TIẾP '
];


/* `configure processor */
var Cache_Image = false; // `save all images from the source to our cache, if false, just fetch the first image
var Auto_Readmore_Len = 1000;


////Global
////######
var Link = '';
var Title = '';
var Content = '';
var Image_Origin = [];
var Image_Replace = [];
var Image_New = [];
var Image_Name = [];
var Image_Total = 0;
var Image_Backup = '';
var Image_Index = 0;
var Video = false;
var Video_Solved = true;
var Permalink = '';
var Draft_Please = false;
var HTML_Please = false;

var Max_Tab = FL.length / 2;
var Cur_HTML = '';
var Tab_HTML = '';
var Cur_Tab = 0;

var Feed_List = [];
var Feed_Total = 0;
var Feed_Index = 0;

var Map_Post = '';
var Auto_Post = true;
var Fetch_Force = '';
var Timer;

var Stream = 0;
var Stream_Index = 0;
var Stream_Link = [];
var Stream_Content = 0;
var Stream_Found = false;

////Add data to DOM to easy work if need '.feeds-parse'
var FP = '.feeds-parse';

// `init localStorage
if (typeof(localStorage.Links) == 'undefined') {
	// `clear the old
	localStorage.clear();
	localStorage.Links = '';
	localStorage.Titles = '';
	localStorage.Force = 'true';
	localStorage.Tab = 0;
	localStorage.Auto = 'false';
}

if (typeof(localStorage.Errors) == 'undefined') {
	localStorage.Errors = '';
}
////PROCESSORS
////##########


function debug(str) {
	//$('.feeds-debug').html($('.feeds-debug').html() + str + '<br/>');
	console.log(str);
}

function error(str) {
	alert(str);
	Pbar_Hide();
/*
	if (localStorage.Auto == 'true') {			
		Feed_Trigger_Click();			
	}
*/
}
function delay(msec) {
	var d = new Date();
	var start = d.getTime();
	while(true) {
		var d = new Date();
		var end = d.getTime();
		if (end - start > msec) {
			return;
		}
	}
}

////Report error to clear cache
function Fetch_Error(data, url) {
	
	//alert('Call FError');
	if (data.indexOf('feeds_get.php') != -1 || data.length == 0) {		
		localStorage.Errors += ',' + url;
		Pbar_Hide();
		debug('Fetch_Error: url='+url + '::data='+data);
		error('Fetch_Error()');
		return true;
	}
	return false;
}


function Check_Cate() {
	var tab_name = ' ' + FL[Cur_Tab * 2];
	var host = ' ' + Get_Host(Link);
	
    
    $('#categorychecklist .selectit').each(function(){
        text = $(this).text();
		
		/* `check source of news */
        if (text.indexOf(host) != -1) {
            $(this).find('input').each(function(){
                $(this).prop('checked', true);
                //$(this).attr('checked', 'checked');
            });
        }		

		/* `check category */
		if (text.indexOf(tab_name) != -1) {
			$(this).find('input').each(function(){
				$(this).prop('checked', true);
				$(this).parents('ul.children').each(function () {
					$(this).parents('li').find('.selectit:first').each(function () {						
						$(this).find('input').each(function(){
							$(this).attr('checked', 'checked');
						});						
					});
				});
			});
		}

		/* `check post type */	
		// if (Video == true) {
			// if (text.indexOf(' Video') != -1) {
				// $(this).find('input').each(function(){
					// $(this).prop('checked', true);					
				// });
			// }
		// }
    });
}


function Check_Tags() {
	
}

/*
function Check_Date() {
	var dt = new Date();
	var j = parseInt(dt.getDate());
	var m = parseInt(dt.getMonth()) + 1;
	var aa = parseInt(dt.getFullYear());
	var h = parseInt(dt.getHours());
	var n = parseInt(dt.getMinutes());
	
	
	// `valid style
	var mm = '';
	if (m < 10) mm = '0' + m;
	else mm = m;
	
	var jj = '';
	if (j < 10) jj = '0' + j;
	else jj = j;
	
	var hh = '';
	if (h < 10) hh = '0' + h;
	else hh = h;
	
	var mn = '';
	if (n < 10) mn = '0' + n;
	else mn = n;
	
	
	// `set month
	$('.timestamp-wrap #mm option').each(function () {
		s = $(this).attr('selected');
		if (s == 'selected') $(this).removeAttr('selected');
		v = $(this).val();
		if (v == mm) {
			$(this).attr('selected', 'selected');			
		}
	});
	
	// `set day
	$('.timestamp-wrap #jj').val(jj);
	
	// `set year
	$('.timestamp-wrap #aa').val(aa);
	
	// `set hour
	$('.timestamp-wrap #hh').val(hh);
	
	// `set minute
	$('.timestamp-wrap #mn').val(mn);
}
*/


function Get_Permalink() {	
	for (var i = 0; i < 10; i++) {
		delay(500);
		$('a#content-html').trigger('click');// `switch to HTML mode
		val = $('.wp-editor-area').val();
		if (val.indexOf('Something is missing here!') == -1) {
			break;
		}
		$('.wp-editor-area').val(Content);
		if (!HTML_Please) {
			delay(500);
			$('#content-tmce').trigger('click');
		}
	}
	if (i == 10) {
		error('Get_Permalink()');
		return;
	}
	                                         
	if ((!Video || (Video && Video_Solved)) && !Draft_Please) {
		//alert('Publish');
		$('input#publish').trigger('click');		
	} else {
		//alert('Save draft');
		$('input#save-post').trigger('click');
	}
		
	return;
}


function Approve_Content() {
	debug('New auto readmore');
	var img_k1 = '<img';
	var img_k2 = '>';
	var img_i1 = Content.indexOf(img_k1,150);// `add 150 to prevent backup image and too short content
	if (img_i1 != -1) {
		debug('found image for auto readmore');
		var img_i2 = Content.indexOf(img_k2,img_i1);
		if (img_i2 != -1) {
			debug('found end tag of image for auto readmore');
			Content = Content.substring(0,img_i2+img_k2.length) + '<!--more-->' +Content.substring(img_i2+img_k2.length);
		}
	} else {
		if (Content.length > Auto_Readmore_Len) {
			debug('Longer than auto readmore limit');
			var div_k = '</div>';var p_k = '</p>';var table_k = '</table>';var span_k = '</span>';
			var div_i = Content.indexOf(div_k,Auto_Readmore_Len);
			var p_i = Content.indexOf(p_k,Auto_Readmore_Len);
			var table_i = Content.indexOf(table_k,Auto_Readmore_Len);
			var span_i = Content.indexOf(span_k,Auto_Readmore_Len);
			var readmore_pos = 10000;
			if (div_i < readmore_pos && div_i > 150) {
				readmore_pos = div_i;key_len = div_k.length;
			}
			if (p_i < readmore_pos && p_i > 150) {
				readmore_pos = p_i;key_len = p_k.length;
			}
			if (table_i < readmore_pos && table_i > 150) {
				readmore_pos = table_i;key_len = table_k.length;
			}
			if (span_i < readmore_pos && span_i > 150) {
				readmore_pos = span_i;key_len = span_k.length;
			}
			if (readmore_pos != 10000) 
			{
				Content = Content.substring(0,readmore_pos+key_len) + '<!--more-->' +Content.substring(readmore_pos+key_len);
			}
		}
	}
	$('.wp-editor-area').val(Content);
	if (!HTML_Please) {
		delay(500);
		$('#content-tmce').trigger('click');
	} else {
		if (localStorage.Auto == 'false') {
			alert('Dont click visual tab');
		}
	}
}



////Make tasks when finish fetch
function Fetched() {
    // while (Content.indexOf('  ') != -1) {
        // Content = Content.replace('  ', ' ');
    // }     
	
    
    /* `Check post option */
    Check_Cate();
	//Check_Date();
	Check_Tags();
	
	/* `update content */
	Content += '<a href="'+Link+'" target="_blank" class="origin-post hide" rel="nofollow">Bài gốc</a>';
	
	var host = ' ' + Get_Host(Link);
	
	for (var i = 0; i < 10 && host.indexOf('.') != -1; i++) {
		index = host.indexOf('.');
		host = host.substring(0,index) + '_' + host.substring(index+1);
	}
	for (var i = 0; i < 10 && host.indexOf(' ') != -1; i++) {
		index = host.indexOf(' ');
		host = host.substring(0,index) +  host.substring(index+1);
	}
	
	
	/*
	host = '_' + host;
	Content = '<div class="'+host+'">'+Content+'</div>';
	*/
	// $('.wp-editor-area').val(Content);
	// $('#content-tmce').trigger('click');// `click visual
	Approve_Content();

	/* `get permalink, when finished: post and update slug 
	Permalink = '';
	Pbar_Update('Waiting permalink...');*/
	
	debug('Video = ' + Video + '::Video_Solved = '+Video_Solved + '::Draft_Please = '+Draft_Please);
	if (localStorage.Auto == 'true') {
		Timer=setInterval(function(){Get_Permalink()},30000);
		Get_Permalink();
	}		
	
	Pbar_Hide();
}

////Process image from external host
function media_feed_process(data) {
	
    if (data.indexOf('feeds_get.php') != -1 || data.length == 0) {
		if (Image_Index == 0) {
			debug('###ERROR:Load first image ##'+Image_Replace[Image_Index]+'##' + data);
			error('media_feed_process()');
			return;
		} else {
			Image_New[Image_Index] = Image_Replace[Image_Index];
		}
	} else {
		Image_New[Image_Index] = data;    
		Image_New[Image_Index] = home_url + '/' + Image_New[Image_Index].substring(2);// `remove .. before url
	}
    Image_Index++;
	
    
    ////Continue index
    if (Image_Index < Image_Total && Cache_Image) {
        Pbar_Update('Fetching: ' + Image_Name[Image_Index]);		
        // $.ajax({
            // url: home_url + '/get',
            // type: 'POST',
            // data: 'url='+UTF8_To_Ascii(Image_Replace[Image_Index]),
            // success: function(data) {
				
            // }
        // });
		$.post(home_url + '/get', {
			url:UTF8_To_Ascii(Image_Replace[Image_Index]),
			force:'false'
		}, 
		function(data){
			if (Fetch_Error(data, UTF8_To_Ascii(Image_Replace[Image_Index]))) {
				data = Image_Replace[Image_Index];
			}
			media_feed_process(data);
		});
    } else {
        ////Process by replace old images
        for (var i = 0; i < Image_Total; i++) {
			if (!Cache_Image && i > 0) {
				Image_New[i] = Image_Replace[i];
			}
			Content = Content.replace('src="'+Image_Origin[i]+'"', 'src="'+Image_New[i]+'"');
        }
		////Display content
        Fetched();
    }
}

////Process first HTML code fetch from rss click
function first_feed_process(data) {
	Content = data;
	// $(FP).html(data);
	// return;
	if (Content.indexOf('404 - ') != -1) {
		debug('File not found: 404 error');
		error('first_feed_process()');
		return;
	}
	debug('### first_feed_process():');
	debug('dlen1 = ' + Content.length);
	
	/* `common remove */
	// debug('Zing content before remove body : ' + Content.indexOf('content_document'));
	Content = Get_Str_Between_Tag(Content, 'body');
	// debug('Zing content at : ' + Content.indexOf('content_document'));
	
	/* `Video detector: test 24h eva, solve: ngoisao, vtc
	############################################## 
	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
	
	
	// `tiin.vn video
	// ~~~~~~~~~~~~~~~~~
	if (Link.indexOf('tiin.vn') != -1) {
		var key = 'movie="/';
		var index = Content.indexOf(key);
		var host_add = 'http://tiin.vn';
		while (index != -1) {
			debug('found ' + key + ' at ' + index);
			Video = true;
			HTML_Please = true;
			Content = Content.substring(0, index-1+key.length) + host_add + Content.substring(index-1+key.length);
			
			var key1 = 'value="/';
			var index1 = Content.indexOf(key1, index + host_add.length);
			if (index1 == -1) {
				Video_Solved = false;
				break;
			}
			Content = Content.substring(0, index1-1+key1.length) + host_add + Content.substring(index1-1+key1.length);
			
			var key1 = 'value="/';
			var index1 = Content.indexOf(key1, index1 + host_add.length);
			if (index1 == -1) {
				Video_Solved = false;
				break;
			}
			Content = Content.substring(0, index1-1+key1.length) + host_add + Content.substring(index1-1+key1.length);
			
			var key1 = 'src="/';
			var index1 = Content.indexOf(key1, index1 + host_add.length);
			if (index1 == -1) {
				Video_Solved = false;
				break;
			}
			Content = Content.substring(0, index1-1+key1.length) + host_add + Content.substring(index1-1+key1.length);
			
			index = Content.indexOf(key, index1 + key.length);
		}
			
	} 
	
	// `sohoa.vnexpress.net video
	// ~~~~~~~~~~~~~~~~~
	if (Link.indexOf('sohoa.vnexpress.net') != -1) {
		////Remove all script
		var tagopen = '<script';
		var tagclose = '</script>';
		
		while (Content.indexOf(tagopen) != -1) {
			Content = Remove_Str_Between_Keys(Content, tagopen, tagclose);
		}  
		//alert('removed script');
		
		////Remove all script
		var tagopen = '<Script';
		var tagclose = '</Script>';
		while (Content.indexOf(tagopen) != -1) {
			Content = Remove_Str_Between_Keys(Content, tagopen, tagclose);
		}  
		$(FP).html(Content);
		$(FP + ' div').each(function () {
			dcv = $(this).attr('data-component-value');
		
			if (typeof(dcv) != 'undefined' && dcv != null) {
				Video = true;
				Video_Solved = true;
				var short_code = '<object height="400" id="fpt_player" width="600" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param value="http://st.f1.sohoa.vnexpress.net/flash/fptplayer_embed.swf" name="movie"><param value="high" name="quality"><param value="transparent" name="wmode"><param value="xmlPath=http://sohoa.vnexpress.net/video/vne-info/id/'+dcv+'&amp;colorAux=0x0099ff&amp;colorBorder=0x333333&amp;colorMain=0xffffff&amp;local=embed&amp;mAuto=false&amp;autoHide=false&amp;trackurl=&amp;tracktype=video" name="flashvars"><param value="true" name="allowfullscreen"><param value="always" name="allowScriptAccess"><embed height="400" width="600" name="fpt_player" src="http://st.f1.sohoa.vnexpress.net/flash/fptplayer_embed.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="transparent" allowscriptaccess="always" allowfullscreen="true" type="application/x-shockwave-flash" flashvars="xmlPath=http://sohoa.vnexpress.net/video/vne-info/id/'+dcv+'&amp;colorAux=0x0099ff&amp;colorBorder=0x333333&amp;colorMain=0xffffff&amp;local=embed&amp;mAuto=false&amp;autoHide=false&amp;trackurl=&amp;tracktype=video"></object>';
				
				$(this).html(short_code);
				$(this).removeAttr('style');
			}
		});	
		Content = $(FP).html();		
	} 
	
	else
	// `kenh14.vn video
	// ~~~~~~~~~~~~~~~~~
	if (Link.indexOf('kenh14.vn') != -1) {
		if (Content.indexOf('mediaplayer.swf') != -1) {
			Video = true;
			Video_Solved = true;
		}
	} 
	
	else
	// `eva.vn video
	// ~~~~~~~~~~~~~~~~~
	if (Link.indexOf('eva.vn') != -1) {
		var key = 'flashWrite("/images/video_clip.swf';
		var index = Content.indexOf(key);
		
		while (index != -1) {
			Video = true;
			
			var key1 = '&file=';
			var index1 = Content.indexOf(key1, index);
			
			if (index1 == -1) {
				Video_Solved = false;
				break;
			}
			
			var key2 = '.mp4&';
			
			var index2 = Content.indexOf(key2, index1);
			
			if (index2 == -1) {
				Video_Solved = false;
				break;
			}
			var file = Content.substring(index1 + key1.length, index2 + key2.length-1);
			
			// `playlist detected
			// if (file.indexOf('mp4,') != -1) {
				// Video_Solved = false;
				// index = Content.indexOf(key, index + key.length);
				// continue;
			// }
			
			
					
			var key3 = '</script>';
			var index3 = Content.indexOf(key3, index2);
						
			var short_code = '';
			if (index3 != -1) {
				short_code = '[pro-player]'+file+'[/pro-player]';
				Content = Content.substring(0, index3 + key3.length) + short_code + Content.substring(index3 + key3.length);
			} else {
				Video_Solved = false;
				break;
			}
			
			index = Content.indexOf(key, index3);
		}
	}
	
	else
	// `dantri.com.vn video
	// ~~~~~~~~~~~~~~~~~
	if (Link.indexOf('dantri.com.vn') != -1) {
		if (Content.indexOf('mediaplayer.swf') != -1) {
			Video = true;
			Video_Solved = true;
		}
	} 
	
	else
	// `vov.vn video
	// ~~~~~~~~~~~~~~~~~
	if (Link.indexOf('vov.vn') != -1) {
		if (Content.indexOf('youtube.com') != -1) {
			Video = true;
			Video_Solved = true;
		} else {
			var key = 'data="/';
			var index = Content.indexOf(key);
			var host_add = 'http://vov.vn';
			while (index != -1) {
				debug('found ' + key + ' at ' + index);
				Video = true;
				HTML_Please = true;
				Content = Content.substring(0, index-1+key.length) + host_add + Content.substring(index-1+key.length);
				
				var key1 = 'file=/';
				var index1 = Content.indexOf(key1, index + host_add.length);
				if (index1 == -1) {
					Video_Solved = false;
					break;
				}
				Content = Content.substring(0, index1-1+key1.length) + host_add + Content.substring(index1-1+key1.length);
				
				index = Content.indexOf(key, index1 + key.length);
			}
		}
	} 
	
	else
	
	// `news.zing.vn video
	// ~~~~~~~~~~~~~~~~~
	if (Link.indexOf('news.zing.vn') != -1) {
		if (Content.indexOf('youtube.com') != -1) {
			Video = true;
			Video_Solved = true;
		}
	} 
	
	else
	// `bongdaplus.vn video
	// ~~~~~~~~~~~~~~~~~
	if (Link.indexOf('bongdaplus.vn') != -1) {
		var key = 'VideoPlaying';
		var index = Content.indexOf(key);
		
		while (index != -1) {
			Video = true;
			
			var key1 = ',\'/';
			var index1 = Content.indexOf(key1, index);
			
			if (index1 == -1) {
				Video_Solved = false;
				index = Content.indexOf(key, index + key.length);
				continue;
			}
			
			var key2 = '.mp4\');';
			
			var index2 = Content.indexOf(key2, index1);
			
			if (index2 == -1) {
				Video_Solved = false;
				index = Content.indexOf(key, index + key.length);
				continue;
			}
			var file = 'http://bongdaplus.vn/' + Content.substring(index1 + key1.length, index2 + key2.length-3);
			
			// `playlist detected
			// if (file.indexOf('mp4,') != -1) {
				// Video_Solved = false;
				// index = Content.indexOf(key, index + key.length);
				// continue;
			// }
			
			
			var key3 = '</script>';
			var index3 = Content.indexOf(key3, index2);
						
			var short_code = '';
			if (index3 != -1) {
				short_code = '[pro-player]'+file+'[/pro-player]';
				Content = Content.substring(0, index3 + key3.length) + short_code + Content.substring(index3 + key3.length);
			} else {
				Video_Solved = false;
				index = Content.indexOf(key, index + key.length);
				continue;
			}
			
			index = Content.indexOf(key, index3);
		}
	}
	else
	
	// `gamethu.vnexpress.net video
	// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	if (Link.indexOf('gamethu.vnexpress.net') != -1) {
			
		var key = 'xmlPath: "';
		var index = Content.indexOf(key);
		
		while (index != -1) {
			Video = true;
			
			var key1 = '",';
			var index1 = Content.indexOf(key1, index);
			if (index1 == -1) {
				Video_Solved = false;
				break;
			}
			var xmlPath = 'http%3A%2F%2Fgamethu.vnexpress.net' + Content.substring(index + key.length, index1);
			
			
			var key2 = 'swfobject.embedSWF("';
			var index2 = Content.indexOf(key2, index1);
			if (index2 == -1) {
				Video_Solved = false;
				break;
			}
			
			http://gamethu.vnexpress.net
			var key3 = '",';
			var index3 = Content.indexOf(key3, index2);
			if (index3 == -1) {
				Video_Solved = false;
				break;
			}
			var embedSWF = 'http://gamethu.vnexpress.net' + Content.substring(index2 + key2.length, index3);
			//alert('embedSWF = ' + embedSWF);
					
			var key4 = '</script>';
			var index4 = Content.indexOf(key4, index3);
			var short_code = '';
			if (index4 != -1) {
				//short_code = '<object type="application/x-shockwave-flash" id="musicplayer" name="player" data="'+embedSWF+'" width="600" height="400"><param name="menu" value="false"><param name="allowfullscreen" value="true"><param name="allowscriptaccess" value="always"><param name="wmode" value="opaque"><param name="flashvars" value="xmlPath='+xmlPath+'&amp;colorAux=0x0099ff&amp;colorBorder=0x333333&amp;colorMain=0xffffff&amp;local=embed&amp;mAuto=false&amp;repeat=false"></object>';
				short_code = xmlPath;
				
				Content = Content.substring(0, index4 + key4.length) + short_code + Content.substring(index4 + key4.length);
			} else {
				Video_Solved = false;
				break;
			}
			
			index = Content.indexOf(key, index4);
		}
		Video_Solved = false;
	} 
	
	// `vnexpress.net video
	// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	if (Link.indexOf('vnexpress.net') != -1) {
		////Remove all script
		var tagopen = '<script';
		var tagclose = '</script>';
		
		while (Content.indexOf(tagopen) != -1) {
			Content = Remove_Str_Between_Keys(Content, tagopen, tagclose);
		}  
		//alert('removed script');
		
		////Remove all script
		var tagopen = '<Script';
		var tagclose = '</Script>';
		while (Content.indexOf(tagopen) != -1) {
			Content = Remove_Str_Between_Keys(Content, tagopen, tagclose);
		}  
		$(FP).html(Content);
		
		$(FP + ' .content #flashContent').each(function () {
			
			Video = true;
			Video_Solved = false;
			/*
			$(FP + ' .content #flashContent span').each(function () {
				id = $(this).attr('id');
				if (id != null) {
					if (id.indexOf('FlashPlayer') != -1) {
						id = Str_Get_After_Key(id, 'FlashPlayer');
						debug(id);
						var object = '<object type="application/x-shockwave-flash" id="musicplayer'+id+'" name="player'+id+'" data="http://vnexpress.net/video/player_local.swf" width="480" height="380"><param name="menu" value="false"><param name="allowfullscreen" value="true"><param name="allowscriptaccess" value="always"><param name="wmode" value="opaque"><param name="flashvars" value="xmlPath=http%3A%2F%2Fvnexpress.net%2FService%2FFlashVideo%2FPlayListVideoPage.asp%3Fid%3D'+id+'%26f%3D83%26t%3D1&amp;colorAux=0x0099ff&amp;colorBorder=0x333333&amp;colorMain=0xffffff&amp;local=embed&amp;mAuto=false&amp;repeat=false&amp;fvalue=83&amp;nid=1002307025"></object>';
						$(FP + ' .content #flashContent').html(object);
						debug(object);
						Video_Solved = true;
					}
				}
			});
			*/
			
		});
		
		
		
	} 
	
	else 
	// `tuoitre.vn video
	// ~~~~~~~~~~~~~~~~~
	if (Link.indexOf('tuoitre.vn') != -1) {
		if (Content.indexOf('youtube.com') != -1 || Content.indexOf('tv.tuoitre.vn') != -1) {
			Video = true;
			Video_Solved = true;
		}
	} 
	
	else
	// `2sao.vn video
	// ~~~~~~~~~~~~~~~~~
	if (Link.indexOf('2sao.vn') != -1) {
		if (Content.indexOf('youtube.com') != -1) {
			Video = true;
			Video_Solved = true;
		}
	} 
	
	else
	// `ngoisao.net video
	// ~~~~~~~~~~~~~~~~~
	if (Link.indexOf('ngoisao.net') != -1) {
		////Remove all script
		var tagopen = '<script';
		var tagclose = '</script>';
		
		while (Content.indexOf(tagopen) != -1) {
			Content = Remove_Str_Between_Keys(Content, tagopen, tagclose);
		}  
		//alert('removed script');
		
		////Remove all script
		var tagopen = '<Script';
		var tagclose = '</Script>';
		while (Content.indexOf(tagopen) != -1) {
			Content = Remove_Str_Between_Keys(Content, tagopen, tagclose);
		}  
		$(FP).html(Content);
		
		// `detect external link to video
		var external_video = false;
		$(FP + ' .PnDTitle').each(function () {
			text = $(this).text();
			if (text != null) {
				if (text.indexOf('Xem video') != -1) {
					external_video = true;
					return;
				}
			}
		});
		if (external_video) {
			debug('ngoisao.net: reject because external link to video');
			error('ngoisao video');
			return;
		}
		
		
		
		$(FP + ' p').each(function () {
			var videoid = $(this).attr('id');
			var key = 'FlashPlayer';
		
			if (typeof(videoid) != 'undefined' && videoid != null) {
				if (videoid.indexOf(key) != -1) {
					videoid = videoid.substring(key.length);
					Video = true;
					Video_Solved = true;
					var short_code = '<object type="application/x-shockwave-flash" id="musicplayer'+videoid+'" name="player'+videoid+'" data="http://ngoisao.net/Service/FlashVideo/fptplayer_embed.swf" width="600" height="400"><param name="menu" value="false"><param name="allowfullscreen" value="true"><param name="allowscriptaccess" value="always"><param name="wmode" value="transparent"><param name="flashvars" value="xmlPath=http://ngoisao.net/Service/FlashVideo/PlayListVideo.asp?id='+videoid+'&amp;colorAux=0x0099ff&amp;colorBorder=0x333333&amp;colorMain=0xffffff&amp;local=embed&amp;mAuto=false&amp;repeat=false"></object>';
					
					$(this).html(short_code);
				}
			}
		});	
		Content = $(FP).html();		
	} 
	
	else 
	// `vtc.vn video
	// ~~~~~~~~~~~~~~~~~
	if (Link.indexOf('vtc.vn') != -1) {
		////Remove all script
		var tagopen = '<script';
		var tagclose = '</script>';
		
		while (Content.indexOf(tagopen) != -1) {
			Content = Remove_Str_Between_Keys(Content, tagopen, tagclose);
		}  
		//alert('removed script');
		
		////Remove all script
		var tagopen = '<Script';
		var tagclose = '</Script>';
		while (Content.indexOf(tagopen) != -1) {
			Content = Remove_Str_Between_Keys(Content, tagopen, tagclose);
		}  
		$(FP).html(Content);
		//alert(Content.length);
		$(FP + ' embed').each(function () {
			var flashvars = $(this).attr('flashvars');
			//alert('flashvars = ' + flashvars);
		
			if (typeof(flashvars) != 'undefined' && flashvars != null) {
				//alert('found');
				Video = true;
				Video_Solved = true;
				var short_code = '<embed id="flvplayer-0" height="400" name="flvplayer" type="application/x-shockwave-flash" width="600" src="http://res.vtc.vn/media/vtcnews/resources/swf/flv/flvplayer.swf" quality="hight" wmode="transparent" allowfullscreen="true" allowscriptaccess="always" flashvars="'+flashvars+'" class="flvplayer">	';
				
				$(short_code).insertAfter($(this));
				$(this).remove();				
			}
			
		});	
		Content = $(FP).html();	
		//alert(Content.length);
	} 
	
	else 
	// `vietnamnet.vn video
	// ~~~~~~~~~~~~~~~~~
	if (Link.indexOf('vietnamnet.vn') != -1) {
		if (Content.indexOf('http://clip.vietnamnet.vn/Lib/player.swf') != -1) {
			Video = true;
			Video_Solved = true;
		}
	} 
	
	else 
	// `24h.com.vn video
	// ~~~~~~~~~~~~~~~~~
	if (Link.indexOf('24h.com.vn') != -1) {
		var key = 'flashWrite("/js/player24H2.swf';
		var index = Content.indexOf(key);
		
		while (index != -1) {
			Video = true;
			
			var key1 = '&file=';
			var index1 = Content.indexOf(key1, index);
			
			if (index1 == -1) {
				Video_Solved = false;
				break;
			}
			
			var key2 = '.mp4&';
			
			var index2 = Content.indexOf(key2, index1);
			
			if (index2 == -1) {
				Video_Solved = false;
				break;
			}
			var file = Content.substring(index1 + key1.length, index2 + key2.length-1);
			
			// `playlist detected
			// if (file.indexOf('mp4,') != -1) {
				// Video_Solved = false;
				// index = Content.indexOf(key, index + key.length);
				// continue;
			// }
			
			
					
			var key3 = '</script>';
			var index3 = Content.indexOf(key3, index2);
						
			var short_code = '';
			if (index3 != -1) {
				short_code = '[pro-player]'+file+'[/pro-player]';
				Content = Content.substring(0, index3 + key3.length) + short_code + Content.substring(index3 + key3.length);
			} else {
				Video_Solved = false;
				break;
			}
			
			index = Content.indexOf(key, index3);
		}
	}
	// debug('Zing content after process video: ' + Content.indexOf('content_document'));
	debug('dlenv = ' + Content.length);
	
	////Remove all script
	var tagopen = '<script';
	var tagclose = '</script>';
	
	while (Content.indexOf(tagopen) != -1) {
		Content = Remove_Str_Between_Keys(Content, tagopen, tagclose);
	}  
	//alert('removed script');
	
	////Remove all script
	var tagopen = '<Script';
	var tagclose = '</Script>';
	while (Content.indexOf(tagopen) != -1) {
		Content = Remove_Str_Between_Keys(Content, tagopen, tagclose);
	}  
	//alert('removed Script');
	
	 ////Remove all script
	var tagopen = '<style';
	var tagclose = '</style>';
	while (Content.indexOf(tagopen) != -1) {
		Content = Remove_Str_Between_Keys(Content, tagopen, tagclose);
	}  
	var tagopen = '<!--';
	var tagclose = '-->';
	while (Content.indexOf(tagopen) != -1) {
		Content = Remove_Str_Between_Keys(Content, tagopen, tagclose);
	}   
	
	debug('dlenx = ' + Content.length);

	////Item fetch session
	//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	// debug('Zing content after process tags: ' + Content.indexOf('content_document'));
	$(FP).html(Content);
	
	$(FP + ' iframe').each(function () {
		src = $(this).attr('src');
		if (src == null) {
			$(this).remove();
			return;
		}
		if (src.indexOf('youtube') == -1) $(this).remove();
	});
	
	
	////kienthuc.net.vn item
	////#############
	if (Link.indexOf('kienthuc.net.vn') != -1) {
		
		if (Link.indexOf('/gallery/') != -1 || Link.indexOf('/anh/') != -1) {
			Stream_Found = true;
		}
		$(FP + ' .gallery-cover').each(function () {
			Stream_Found = true;
		});
		if (Stream_Found) {
			/*
			if (Stream == 0) {
				debug('Stream found');
				Stream_Index = 1;
				Stream_Content = '';
				$(FP + ' .content_ref').remove();
				$(FP + ' .box-wiget-content-cover').each(function () {
					Stream_Content += '<h2 class="Lead">' + $(this).html() + '</div>';
					Stream_Content = Stream_Content.replace('(Kienthuc.net.vn) - ', '');
					Stream_Content = Stream_Content.replace('(Kienthuc.net.vn)', '');
					Stream_Content = Stream_Content.replace('- ', '');
					debug(Stream_Content);
					//debug('Content fish : ' + $(this).html());
				});
				$(FP + ' .gallery-pagination ul li a').each(function () {
					Stream_Link[Stream] = $(this).attr('href');
					Stream++;
				});
				
				debug('Stream = ' + Stream);
				for (var i = 0; i < Stream; i++) {
					debug('Stream Link '+i+' = ' + Stream_Link[i]);
				}
				if (Stream == 0) {
					debug('Blank stream detected');
					error('kienthuc blank stream');
					return;
				}
			}
			$(FP + ' .gallery-cover a').remove();			
			$(FP + ' .gallery-cover').each(function () {
				Stream_Content += $(this).html();
				debug('Content add each : ' + $(this).html());
			});
			debug('Stream_Index , Stream : ' + Stream_Index + ', ' + Stream);
			if (Stream_Index < Stream) {
				debug('Call new stream');
				$.post(home_url + '/get', {
					url:UTF8_To_Ascii(Stream_Link[Stream_Index]),
					force:'true'
				},
				function(data){
					debug('Finished load stream ' + Stream_Index);
					Stream_Index++;
					first_feed_process(data);
					return;
				});
				return;
			}
			
			Content = Stream_Content;
			debug(Stream_Content);
			*/
			Content = '';
			$(FP + ' #list_order').remove();
			$(FP + ' .box-wiget-content-cover').each(function () {
				Content += '<h2 class="Lead">' + $(this).text() + '</h2>'; 
				Content = Content.replace('(Kienthuc.net.vn) - ', '');
				Content = Content.replace('(Kienthuc.net.vn)', '');
				Content = Content.replace('- ', '');
			});
			$(FP + ' ul#gallery li').each(function () {
				Content += $(this).html();
			});
			debug(Content);
			
		} else {
			debug('Not a stream');
			$(FP +' .content_ref').remove();
			Content = '';
			$(FP +' #ctl02_ctl00_lblDesciption').each(function () {
				debug('???????');
				Content += '<h2 class="Lead">' + $(this).html() + '</h2>'; 
				debug(Content);
				Content = Content.replace('(Kienthuc.net.vn) - ', '');
				Content = Content.replace('(Kienthuc.net.vn)', '');
				Content = Content.replace('- ', '');
				debug(Content);
			});
			
			$(FP + ' strong').each(function () {
				html = $(this).html();
				if (html != null) {
					if (html.indexOf('ĐANG ĐỌC NHIỀU') != -1 || html.indexOf('TIN LIÊN QUAN') != -1) {
						$(this).remove();
					}
				}
			});
			
			$(FP +' .entry-content').each(function () {
				Content += $(this).html(); 
			});			
		}
		Stream = 0;
		Stream_Found = false;
	}                        
	else
	
	////tiin.vn item
	////#############
	if (Link.indexOf('tiin.vn') != -1) {
		$(FP +' #title-container').remove();
		$(FP +' .fb-like').remove();
		$(FP +' #related-link-container').remove();
		Content = '';
		$(FP +' #body-content').each(function () {
			Content += $(this).html(); 
		});
	}                        
	else
	
	////baodatviet.vn item
	////#############
	if (Link.indexOf('baodatviet.vn') != -1) {
		debug('bao dat viet item:');
		Content = '';
		$(FP +' .detail_sapo').each(function () {
			Content += '<h2 class="Lead">' + $(this).html() + '</h2>'; 
		});
		$(FP +' .detail_summary').each(function () {
			Content += $(this).html(); 
		});
		$(FP +' .detail_author').each(function () {
			Content += '<p class="true-author">'+$(this).html()+'</p>'
		});
		
		index1 = 0;
		key1 = '<a';
		key2 = '</a>';
		key3 = '<br>';
		for (var i = 0; i < 10; i++) {
			index1 = Content.indexOf(key1,index1);
			if (index1 == -1) break;
			debug('Found open external link at ' + index1);
			index2 = Content.indexOf(key2,index1);
			if (index2 == -1) break;
			debug('Found close external link at ' + index2);
			index3 = Content.indexOf(key3,index2);
			debug('Found exactly external link at ' + index3);
			if (index3 == index2+key2.length) {
				debug('Remove external link');
				Content = Content.substring(0,index1) + Content.substring(index3 + key3.length);
			} else {
				index1++;
			}
		}
	}                        
	else
	
	////vntimes.com.vn item
	////#############
	if (Link.indexOf('vntimes.com.vn') != -1) {
		$(FP +' ul li a').remove();
		$(FP +' .date-detail').remove();
		$(FP +' h1').remove();
		$(FP +' .banquyen').remove();
		
		Content = $(FP +' .news-detail').html(); 

	}                        
	else
	
	////tinmoi.vn item
	////#############
	if (Link.indexOf('tinmoi.vn') != -1) {
		$(FP + ' div').each(function () {
			divid = $(this).attr('id');
			if (typeof(divid) != 'undefined' && divid != null) {
				if (divid.indexOf('div-gpt-ad') != -1) {
					$(this).remove();
				}
			}
		});
		$(FP +' .box-news-top').remove();
		$(FP +' .box-news-suggest').remove();
		$(FP +' iframe').remove();
		$(FP +' .box-news-top').remove();
		$(FP +' p').each(function () {
			text = $(this).text();			
			if (text != null) {
				if (text.indexOf('Tin liên quan') != -1) {
					$(this).remove();
				}
			} 			
		});
		$(FP +' p').each(function () {
			html = $(this).html();			
			if (html != null) {
				if (html.indexOf('line_03.png') != -1) {
					$(this).remove();
				}
			} 			
		});
		
		
		Content = $(FP +' #tm-content').html(); 

	}                        
	else
	
	////archi.vn item
	////#############
	if (Link.indexOf('archi.vn') != -1) {
		
		$(FP +' .related-news').remove();		
		Content = '';
		Content = '<h2 class="Lead">' + $(FP +' #article h2:first').html() + '</h2>'; 
		Content += $(FP +' #divContent').html(); 		
	}                        
	else
	
	////batdongsan.com.vn item
	////#############
	if (Link.indexOf('batdongsan.com.vn') != -1) {
		
		$(FP +' .event-list-item').remove();
		Content = '';
		Content = '<h2 class="Lead">' + $(FP +' .summary-detail-art').html() + '</h2>'; 
		Content += $(FP +' #content-art').html(); 
	}                        
	else
	
	////dothi.net item
	////#############
	if (Link.indexOf('dothi.net') != -1) {
		debug('dothi.net:');
		Content = '';
		
		$(FP + ' table').each(function () {
			bgc = $(this).css('background-color');
			debug(bgc);
			if (bgc == 'rgb(245, 237, 172)') {
				$(this).remove();
			}
		});
		
		$(FP +' .boxShareColLeft p:first').each(function () {
			$(this).parent('div').each(function () {
				Content = $(this).html();
			});
		});
		
		index1 = 0;
		key1 = '&gt;&nbsp;<a';
		key2 = '</a>';
		for (var i = 0; i < 10; i++) {
			index1 = Content.indexOf(key1, index1);
			if (index1 == -1) break;
			debug('Found external link at ' + index1);
			index2 = Content.indexOf(key2, index1);
			if (index2 == -1) break;
			debug('Found close tag external link at ' + index2);
			Content = Content.substring(0, index1) + Content.substring(index2 + key2.length);
			index1 += key1;
		}
		
		
		Content = Content.replace('Các bài liên quan:','');
		Content = Content.replace('Xem thêm:','');
		while(Content.indexOf('<p>&gt;') != -1) {
			Content = Remove_Str_Between_Keys(Content,'<p>&gt;', '</p>');
		}
	}                        
	else
	
	
	////BONGDAPLUS.VN item
	////#############
	if (Link.indexOf('bongdaplus.vn') != -1) {
		$(FP +' .story-photo div').remove();
		$(FP +' #audioplayer').remove();
		$(FP +' .story-body strong:first').remove();
		Content = '<h2 class="Lead">' + $(FP +' .article div.sapo').html() + '</h2>';                                   			
		Content += $(FP +' .story-photo').html();  
		Content += $(FP +' .story-body').html();  
	}                        
	else
	
	
	////KENH14.VN item
	////#############
	if (Link.indexOf('kenh14.vn') != -1) {
		debug('kenh14.vn item:');
		// `detect related box
		var related_box = false;
		$(FP + ' .postpadding .content *').each(function(){
			html = $(this).html();
			key = 'Bạn có thể xem thêm:';
			if (html != null) {
				if (html.length <= key.length + 10) {
					if (html.indexOf(key) != -1) {
						$(this).remove();
						debug('found related post');
						related_box = true;
						return;
					}
				}
			}			
		});
		
		
		if (related_box) {
			$(FP + ' .postpadding .content hr:last').remove();
			$(FP + ' .postpadding .content div').each(function () {
				style = $(this).attr('style');
				align = $(this).attr('align');
				var found = false;
				
				if (style != null) {
					if (style.indexOf('text-align') != -1 && style.indexOf('center') != -1) {
						found = true;						
					}
				}
				if (align == 'center') {
					found = true;
				}
				if (found) {
					var must_remove = false;
					$(this).find('a').each(function () {
						target = $(this).attr('target');
						if (target == '_blank') {
							$(this).find('img').each(function () {
								debug('must remove');
								must_remove = true;
							});
						}
					});
					if (must_remove) $(this).remove();
				}
			});
		}
		
		// remove ads box
		$(FP + ' .postpadding .content .div-c .postpadding').each(function () {
			text = $(this).text();
			if (text != null) {
				if (text.indexOf('Discoblog') != -1) {
					$(this).parent('.div-c').remove();
				}
			}
		});
		
		$(FP + ' .postpadding .content table').each(function () {
			text = $(this).text();
			if (text != null) {
				if (text.indexOf('Discoblog') != -1) {
					$(this).remove();
				}
			}
		});
		
		$(FP + ' .postpadding .content .div-c div').each(function () {
			align = $(this).attr('align');
			if (align == 'center') {
				text = $(this).text();
				if (text != null) {
					if (text.indexOf('Discoblog') != -1) {
						$(this).parent('.div-c').remove();
					}
				}
			}
		});
		
		Content = '<h2 class="Lead">' + $(FP +' .postpadding .sapo').html() + '</h2>'; 
		Content += $(FP +' .postpadding .content').html();  
		
	}                        
	else
	
	
	////EVA.VN item
	////#############
	if (Link.indexOf('eva.vn') != -1) {
		
		$(FP + ' em').each(function () {
			text = $(this).text();
			if (text == '(Bấm vào đây để ngắm nhìn)') {
				$(this).remove();
			}
		});
		
		$(FP + ' table td').each(function () {
			bgc = $(this).attr('bgcolor');
			if (bgc == '#ffcccc') $(this).remove();
		});
		
		// `Image slide show dectected
		checkImageslide = $(FP +' .showAnh').html();		
		if (typeof(checkImageslide) != 'undefined' && checkImageslide != null) {
			debug('Stream found');
			if (Stream == 0) {
				Stream = 1;
				Stream_Content = '';
				$(FP + ' .image-footer').each(function () {
					Stream_Content += '<h2 class="Lead">'+$(this).html()+'</h2>';
					debug(Stream_Content);
				});
			}
			$(FP + ' #MainIMG').each(function () {
				src = $(this).attr('src');
				alt = $(this).attr('alt');
				debug(src);debug(alt);
				Stream_Content += '<img src="'+src+'"/><div class="img-caption">'+alt+'</div>';
				debug(Stream_Content);
			});
			var new_stream = false;
			var new_stream_link = '';
			$(FP + ' .xemAnhList a').each(function () {
				text = $(this).text();
				if (text == '>>') {
					new_stream = true;
					new_stream_link = 'http://www.eva.vn' + $(this).attr('href');
					debug(new_stream_link);
				}
			});
			
			if (new_stream) {
				debug('Call new stream');
				$.post(home_url + '/get', {
					url:UTF8_To_Ascii(new_stream_link),
					force:'true'
				},
				function(data){
					debug('Finished load stream ' + Stream);
					Stream++;
					first_feed_process(data);
					return;
				});
				return;
			}
			Content = Stream_Content;
		} else {
			//Normal news
			$(FP +' .title_sapo_news').remove();
			$(FP +' .left_details').remove();
			$(FP +' .publication_date').remove();
			$(FP +' .copyRights').remove();
			$(FP +' .fb_reset').remove();
			$(FP +' .lineFacebook.facebook_embed').remove();
			$(FP +' .article_banner').remove();
			$(FP +' #tag_content').remove();
			$(FP +' .xemTiep').remove();
			$(FP +' .shareFB-green').remove();
			$(FP +' .baiviet-tags').remove();
			$(FP +' #link_details').remove();
			$(FP +' div').each(function () {
				date = $(this).attr('data-zone-id');
				if (typeof(date) != 'undefined' && date != null) $(this).remove();
			});
			
			
		
			//$(FP +' #baiviet-container div:first').remove();//Remove sharing box
			
			// `remove related table
			var has_related = false;
			$(FP +' #baiviet-container table').each(function () {
				if (has_related == false) {
					text = $(this).text();
					if (text != null) {
						if (text.indexOf('Hãy cùng đón đọc sự kiện') != -1) {
							has_related = true;
							$(this).remove();
						}
					}
				} else {
					$(this).remove();
				}
				
			});
			
			
			$(FP +' .xemTiep').remove();
			$(FP +' .rate').remove();
			$(FP +' .baiviet-tags').remove();
			$(FP +' #link_details').remove();
			$(FP +' #comment_content').remove();
			$(FP +' #ads_center_banner').remove();
			$(FP +' .top_box_focus').remove();
			$(FP +' #box_bailienquan').remove();
			$(FP +' .ads_special_center').remove();
			$(FP +' #baiviet-container #news_hot_eva').remove();
			$(FP +' #baiviet-container .news_hot_eva').remove();
			$(FP +' #box_tinnoibatngang_dnv').remove();
			$(FP +' #box_bai_nhieu_nguoi_doc_ngang').remove();
			$(FP +' .info_footer').remove();
			$(FP +' script').remove();
			
			
			Content = '<h2 class="Lead">' + $(FP +' .txt_sapo_news_details strong').html() + '</h2>';                                  			
			Content += $(FP +' #baiviet-container').html();		
			Content += '<p class="true-author">'+$(FP +' .nguontin').html()+'</p>';  
			$(FP).html(Content);
			$(FP + ' .nguontin').remove();
			Content = $(FP).html();
			// `reject if it's an ads
			if (Content.indexOf('Số điện thoại') != -1 || Content.indexOf('Website: ') != -1 || Content.indexOf('facebook: ') != -1) {
				debug('Eva content has ads insided');
				error('Eva has ads');	
				return;
			}
		}
	}                        
	else
	
	
	////IONE.VNEXPRESS.NET item
	////#############
	if (Link.indexOf('ione.vnexpress.net') != -1) {
		var reject_news = false;
		
		$(FP + ' .SubTitle').each(function(){
			text = $(this).text();
			if (text == 'Cười vỡ bụng') {
				reject_news = true;
				return;
			}
		});
		$(FP + ' .ulBackPack .first h3').each(function(){
			text = $(this).text();
			if (text == 'CƯỜI VỠ BỤNG') {
				reject_news = true;
				return;
			}
		});
		if (reject_news) {
			debug('Not expect cate: Cười vỡ bụng');
			error('ione bad cate');
			return;
		}
		
		$(FP +' .RelatedLeadSubject').remove();
		$(FP +' .dtContent .Title').remove();
		$(FP +' .timePost').remove();
		$(FP +' .copyRights').remove();
		$(FP +' .fb_reset').remove();
		$(FP +' .lineFacebook.facebook_embed').remove();
		$(FP +' .article_banner').remove();
		$(FP +' #tag_content').remove();
		$(FP +' div').each(function () {
			date = $(this).attr('data-zone-id');
			if (typeof(date) != 'undefined' && date != null) $(this).remove();
		});
		$(FP + ' div').each(function(){
			data = $(this).html();
			if (data == 'Theo dòng sự kiện:') {
				console.log('Found');
				$(this).parent('div').remove();
			} else if (data != null && data.length < 100) {
				console.log(data);
			}
		});
		$(FP + ' font').each(function () {
			$(this).parents('table').remove();
		});
		$(FP + ' p').each(function () {
			align = $(this).attr('align');
			if (align == 'right') {
				$(this).addClass('true-author');
			}
		});
		Content = $(FP +' .dtContent').html();                                   			
	}                        
	else
	
	
	////DANTRI.COM.VN item
	////#############
	if (Link.indexOf('dantri.com.vn') != -1) {
		$(FP +' a').each(function () {
			text = $(this).text();
			if (text.indexOf('>>') != -1) {
				$(this).remove();
			}
		});
		Content = '<h2 class="Lead">' + $(FP +' .fl .fon33.mt1').html() + '</h2>';
		Content = Content.replace('(Dân trí) - ', '');
		Content += $(FP +' .fl .fon34.mt3.mr2.fon43').html();         
		
	}                        
	else
	
	
	////VOV.VN item
	////#############
	if (Link.indexOf('vov.vn') != -1) {
		// debug('VOV debug');
		$(FP +' .article .story-listing').remove();
		$(FP +' .article .social').remove();
		$(FP +' .article .subtitle').remove();
		$(FP +' .article .title').remove();				
		
		Content = $(FP +' .article').html();
		key = '(VOV) - ';
		index = Content.indexOf(key);
		if (index != -1) {
			Content = Content.substring(0,index) + Content.substring(index+key.length);
		}                  			
	}                        
	else
	
	////NEWS.ZING.VN item
	////#############
	if (Link.indexOf('news.zing.vn') != -1) {
		
		$(FP +' .share_buttons').remove();
		$(FP +' #starbuzzCards').remove();
		$(FP +' .tags').remove();
		$(FP +' .more_news').remove();
		$(FP +' .pTitle').remove();
		$(FP +' div').each(function () {
			id = $(this).attr('id');
			if (typeof(id) != 'undefined') {
				if (id.indexOf('div-gpt-ad') != -1) {
					$(this).remove();
				}                    
			}
		});
		
		Content = $(FP +' #content_document').html();                    
	}                        
	else
	////GAMETHU.vnexpress.net item
	////#############
	if (Link.indexOf('gamethu.vnexpress.net') != -1) {
		$(FP +' .SubTitle').remove();
		$(FP +' .Title').remove();	 
		$(FP +' span').each(function () {
			spanid = $(this).attr('id');
			if (typeof(spanid) != 'undefined' && spanid != null) {
				if (spanid.indexOf('FlashPlayer') != -1) {
					$(this).remove();
				}
			}
		});	 
		$(FP +' div').each(function () {
			divid = $(this).attr('id');
			if (typeof(divid) != 'undefined' && divid != null) {
				if (divid.indexOf('tdTopic') != -1) {
					$(this).remove();
				}
			}
		});	 
		
		$(FP +' div').each(function () {
			cc = $(this).attr('cpms_content');
			if (typeof(cc) != 'undefined' && cc != null) {
				Content = $(this).html();
			}
		});
	}         
	else
	
	////SOHOA.vnexpress.net item
	////#############
	if (Link.indexOf('sohoa.vnexpress.net') != -1) {  			 
		Content = '<h2>' + $(FP +' .dt-pts').html() + '</h2>';
		Content += $(FP + ' #article_content').html();  	
	}         
	else        
	
	////VNEXPRESS.NET item
	////#############
	if (Link.indexOf('vnexpress.net') != -1) {
		$(FP +' h2.Lead a').remove();
		$(FP +' h1.Title').remove();
		$(FP +' .email-print').remove();
		$(FP +' h2.Lead').html(function (index, html) {
			if (html.indexOf('<br') != -1) {
				html = Str_Get_Before_Key(html, '<br');
			}
			return html;
		});
		Content = $(FP +' div.content div:first').html();			
	} 
	////24H.COM.VN item
	////##########
	else if (Link.indexOf('24h.com.vn') != -1) {
		// `Image slide show detected
		checkImageslide = $(FP +' .showAnh').html();
		if (typeof(checkImageslide) != 'undefined' && checkImageslide != null) {
			debug('Slide show detected on "'+Link+'"');
			error('24h slide show');
			return;
		}
		//Content = Get_Str_Between_Keys(Content, '<div class="boxBaiViet-c">', '<div class="boxDon-sub-b">');
		//alert('got 1');
		
		//$(FP).html(Content);
		
		
		image = $(FP + ' .boxBaiViet-c .baivietMainBox-img200').html();
		header = $(FP + ' .baiviet-head-noidung').html();
		text = $(FP + ' .text-conent').html();
		source = $(FP + ' .nguontin').html();
		Content = '';
		
		if (image != null) {
			Content += '<div class="baivietMainBox-img200">'+ image +'</div>';
		}
		if (typeof(header) != 'undefined') {
			header = Str_Get_After_Key(header, '(Tin tuc) - ');
			Content += '<h2 class="Lead">' + header + '</h2>';
		}
		//alert('got 2');
		
		if (text != null) {
			Content += text;
		} else {
			debug('Not found content');
			error('24h content bad');
			return;
		}
		if (source != null) {
			Content += '<p class="true-author">' + source + '</p>';
		}                                     
	}
	////VTC.VN item
	////##########
	else if (Link.indexOf('vtc.vn') != -1) {

		$(FP + ' a.tinlienquan').each(function () {
			$(this).parents('table').remove();
		});  
	
		Content = $(FP + ' #pageContent').html();
		// `detect another page type
		if (Content == null) {
			Content = $(FP + ' #pictureGallery');
			// `Gallery images
			if (Content != null) {
				Content = '';
				$(FP + ' #pictureGallery .carousel-item a').each(function () {
					rel = $(this).attr('rel');
					Content += '<p>';
					Content += '<img class="pictureShow" src="'+rel+'"/>';
					$(this).find('img').each(function () {
						title = $(this).attr('title');
						if (typeof(title) != 'undefined' && title != null) {
							Content += '<span class="pictureCaption">'+title+'</span>'
						}
						
					});
					Content += '</p>';
				});
				Content = '<div class="pictureGallery">' + Content + '</div>';
			}
		}
	}
	////VIETNAMNET.VN item
	////##########
	else if (Link.indexOf('vietnamnet.vn') != -1) {
		Cache_Image = true;
		$(FP + ' img').each(function () {
			src = $(this).attr('src');
			if (typeof(src) != 'undefined') {
				if (src.indexOf('http://img.vietnamnet.vn/logo.gif') != -1) {
					$(this).remove();
				}
			}
		});       
		$(FP + ' a').each(function () {
			text = $(this).text();
			
			if (text.indexOf('>>') != -1) {
				
				$(this).parents('strong').remove();
				$(this).remove();
			}
		});
		$(FP + ' strong').each(function () {
			text = $(this).text();
			if (text.indexOf('TIN BÀI KHÁC:') != -1 || text.indexOf('TIN BÀI LIÊN QUAN:') != -1) {
				text = text.replace('TIN BÀI KHÁC:' ,'');
				text = text.replace('TIN BÀI LIÊN QUAN:' ,'');
				$(this).text(text);
			}
			
		}); 
		
		$(FP + ' div a').remove();
		
		$(FP + ' div').each(function () {
			id = $(this).attr('id');
			if (id != null) {
				if (id.indexOf('survey') != -1) {
					$(this).remove();
				}
			}
		});    
		$(FP + ' em').each(function () {
			text = $(this).text();
			if (text != null) {
				if (text.substring(text.length-1) == '.') {
					$(this).html('<em style="display:block; padding: 0 0 10px 0">' + $(this).text() + '</em>');
				}
			}
		});
		
		Content = $(FP + ' .article_content').html();
	}
	////NGOISAO.NET item
	////##########
	else if (Link.indexOf('ngoisao.net') != -1) {
		$(FP +' .detailCT .topDetail').remove();
		$(FP +' .detailCT .Title').remove();
		$(FP +' .detailCT .RelatedLeadSubject').remove();
		$(FP +' .detailCT .detailNS').remove();
		$(FP +' .detailCT .relateNewsDetail').remove();
		$(FP +' .detailCT .Lead').each(function () {
			text = $(this).text();
			if (text != null) {
				if (text.indexOf('>> ') != -1) {
					$(this).remove();
				}
			}
		});
		Content = $(FP + ' .detailCT').html();
	}
	////2SAO.VN item
	////##########
	else if (Link.indexOf('2sao.vn') != -1) {
		
		$(FP +' .tags').remove();
		$(FP +' .vote_default').remove();
		
		Content = $(FP + ' .spshare').html();
		Content += $(FP + ' .detail_content').html();
	}
	////TUOITRE.VN item
	////##########
	else if (Link.indexOf('tuoitre.vn') != -1) {
		$(FP +' .pTitle').remove();
		$(FP +' #winMediaPlayerID').remove();
		$(FP +' .pBody font, '+FP +' .pBody span').each(function () {
			var text = $(this).text();
			if (text != null) {
				if (text.indexOf('>>') != -1) {
					$(this).parents('.pBody').remove();
				}
			}
		});
		

		Content = $(FP + ' #divContent').html();            
	}
	
	/*
	////COMMON REMOVE after process
	////Remove internal links
	var tagopen = '<A ';
	var tagclose = '</A>';
	while (Content.indexOf(tagopen) != -1) {
		Content = Remove_Tag_Wrap(Content, tagopen, tagclose);
	}      
	//alert('removed internal links');
	
	////Remove internal links
	var tagopen = '<a ';
	var tagclose = '</a>';
	while (Content.indexOf(tagopen) != -1) {
		Content = Remove_Tag_Wrap(Content, tagopen, tagclose);
	}   
	//alert('removed internal links2');
	*/
	 
	if (Content != null) {
		debug('dlens = ' + Content.length);
		if (Content.length < 300) {
			debug('Content too short after process item');
			error('content bad');
			return;
		}
	} else {
		debug('Null Content after process item');
		error('content null');
		return;
	}
	////Remove internal links
	var tagopen = '<a ';
	var tagclose = '</a>';
	while (Content.indexOf(tagopen) != -1) {
		Content = Remove_Tag_Wrap(Content, tagopen, tagclose);
	}  
	// `remove space symbol
	while (Content.indexOf('&nbsp;') != -1) {
		Content = Content.replace('&nbsp;', ' ');
	}
	// `remove feed line symbol
	for (var i = 0; i < Content.length; i++) {
		if (Content.charCodeAt(i) == 10) {
			Content = Content.substring(0,i) + ' ' +Content.substring(i+1);
		}
	}
	
	// `remove wrong HTML standard tags
	// `################################
	var key1 = '<strong';
	var key2 = '</strong><br>';
	for (var i = 0; i < 20 && Content.indexOf(key2) != -1; i++) {
		var index2 = Content.indexOf(key2);
		// alert('['+i+']='+index2);
		var index1 = -1;
		for (var j = 1; j < 20 && (index2 - j * key1.length >= 0); j++) {
			index1 = Content.indexOf(key1,index2 - j * key1.length);
			// alert('J['+j+'] offset['+j*key1.length+']::'+index1);
			if (index1 != -1 && index1 < index2) break;
			index1 = -1;
		}
		if (index1 != -1) {
			index1_close = Content.indexOf('>',index1);
			Content = Content.substring(0,index1) + '<h2 class="heading">' + Content.substring(index1_close+1, index2) + '</h2>' + Content.substring(index2 + key2.length);		
		}
	}
	
	var key1 = '<span';
	var key2 = '</span><br>';
	for (var i = 0; i < 20 && Content.indexOf(key2) != -1; i++) {
		var index2 = Content.indexOf(key2);
		// alert('['+i+']='+index2);
		var index1 = -1;
		for (var j = 1; j < 20 && (index2 - j * key1.length >= 0); j++) {
			index1 = Content.indexOf(key1,index2 - j * key1.length);
			// alert('J['+j+'] offset['+j*key1.length+']::'+index1);
			if (index1 != -1 && index1 < index2) break;
			index1 = -1;
		}
		if (index1 != -1) {
			index1_close = Content.indexOf('>',index1);
			Content = Content.substring(0,index1) + '<h2 class="heading">' + Content.substring(index1_close+1, index2) + '</h2>' + Content.substring(index2 + key2.length);		
		}
	}
	var key1 = '<br><br>';
	var replace_key = '<div fake="br"></div>';
	var index1 = 0;
	for (var i = 0; i < 10 && Content.indexOf(key1,index1) != -1; i++) {
		index1 = Content.indexOf(key1,index1);
		// debug('Found['+i+'] a douple br at ' + index1);
		// alert('Content Before::' + Content);
		Content = Content.substring(0,index1) + replace_key + Content.substring(index1 + key1.length);
		// alert('Content After::' + Content);	
		index1 = index1 + replace_key.length;		
	}
		
	
	
	$(FP).html(Content);

		
	// `Remove blank elements
	//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%	
	$(FP + ' br').remove();
	var blank_tags_list = ['strong', 'span', 'p', 'div', 'td', 'tr', 'tbody', 'table'];
	for (var i = 0; i < blank_tags_list.length; i++) {
		// debug('###checking blank tag['+i+'] = '+blank_tags_list[i]);
		$(FP + ' ' + blank_tags_list[i]).each(function () {
			fake = $(this).attr('fake');
			if (fake != null) {
				return;
			}
			text = $(this).html();
			
			if (text==null || text.length == 0 || text == ' '|| text == '  ' || text == '   ' || text == '    ') {
				// debug('blank_remove['+i+'] with text = ' + text);
				$(this).remove();
			}
		});
		$(FP + ' ' + blank_tags_list[blank_tags_list.length - 1 - i]).each(function () {
			fake = $(this).attr('fake');
			if (fake != null) {
				return;
			}
			text = $(this).html();
			
			if (text==null || text.length == 0 || text == ' '|| text == '  ' || text == '   ' || text == '    ') {
				// debug('blank_remove['+i+'] with text = ' + text);
				$(this).remove();
			}
		});
	}
	
	// `remove link wrap image
	Clear_Image_Links();
	
	// `Remove style elements
	//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	$(FP + ' *').css('font-size', '');
	$(FP + ' *').css('font-family', '');
	
	Content = $(FP).html();
	
	
	if (Content != null) {
		debug('dlenb = ' + Content.length);
		if (Content.length < 300) {
			debug('Content too short after clear blank');
			error('remove blank bad');
			return;
		}
	} else {
		debug('Null Content after clear blank');
		error('remove blank null');
		return;
	}
	
	

	// `insert image if has no image and has a backup
	if (Content.indexOf('<img') == -1 && Image_Backup != '') {
		Content = '<div class="hide backup-thumb"><img src="'+Image_Backup+'"/></div>' + Content;
		debug('Insert Backup image');
	}
	
	
	debug('>>> media process:');
	
	////Get media
	var temp = Content;
	while (temp.indexOf('<img') != -1) {                
		Image_Origin[Image_Total] = Str_Get_After_Key(temp, '<img');
		Image_Origin[Image_Total] = Str_Get_After_Key(Image_Origin[Image_Total], 'src="');
		temp = Image_Origin[Image_Total];
		Image_Origin[Image_Total] = Str_Get_Before_Key(Image_Origin[Image_Total], '"');
		//Image_Replace[Image_Total] = Nake_Url(Image_Origin[Image_Total]);
		Image_Replace[Image_Total] = Image_Origin[Image_Total];
		debug('Image_Origin['+Image_Total+'] = ' + Image_Origin[Image_Total]);
		
		debug('char_before[0]+[1] = ' + Image_Replace[Image_Total].charCodeAt(0) + ' + ' + Image_Replace[Image_Total].charCodeAt(1));
		for (var i = 0; i < 10; i++) {
			if (Image_Replace[Image_Total].charCodeAt(0) < 32) {
				Image_Replace[Image_Total] = Image_Replace[Image_Total].substring(1);
			} else {
				break;
			}
		}
		debug('char_after[0]+[1] = ' + Image_Replace[Image_Total].charCodeAt(0) + ' + ' + Image_Replace[Image_Total].charCodeAt(1));
		
		host = Get_Host(Image_Replace[Image_Total]);
		debug('Image_Total = ' + Image_Total);
		debug('host 1 = ' + host);
		
		if (host.indexOf('.com') == -1 &&  host.indexOf('.net') == -1 &&  host.indexOf('.vn') == -1 ) {
			host = Get_Host(Link);
			debug('host wrong, I got a new as: '+host);
			
			// `remove blank char
			if (Image_Replace[Image_Total].charCodeAt(0) == 32) {
				Image_Replace[Image_Total] = Str_Get_After_Key(Image_Replace[Image_Total], '/') ;
			}
			Image_Replace[Image_Total] = host + '/' + Image_Replace[Image_Total];
		} else {
			Image_Replace[Image_Total] = Image_Origin[Image_Total];
		}
		
		if (Image_Replace[Image_Total].indexOf('http://') == -1 && Image_Replace[Image_Total].indexOf('https://') == -1) {
			Image_Replace[Image_Total] = 'http://' + Image_Replace[Image_Total];
		}
	
		debug('Image_Replace['+Image_Total+'] = ' + Image_Replace[Image_Total]);
		Image_Name[Image_Total] = Get_Image_Name(Image_Replace[Image_Total]);
		Image_New[Image_Total] = '';
		
		Image_Total++;
	}                     
	
	
	if (Image_Total == 0 || (Image_Total < 2 && Video == false)) {
		debug('Not found image');
		if (localStorage.Auto == 'true') {			
			Feed_Trigger_Click();			
		}
		return;
		////Display content
		Fetched();
		
	} else {
		////Replace media
		//alert(Image_Replace[Image_Index]);
		Pbar_Update('Fetching: ' + Image_Name[Image_Index]);	
		debug('first image = ' + Image_Replace[Image_Index]);
		debug('first image (ASCII) = ' + UTF8_To_Ascii(Image_Replace[Image_Index]));
		$.post(home_url + '/get', {
			url:UTF8_To_Ascii(Image_Replace[Image_Index]),
			force:'true'
		},
		function(data){
			media_feed_process(data);
		});
	}					
}

function Feed_Trigger_Click() {
	if ($('.feeds-wrapper .item a').length == 0) {	
		// `for debug:
		//localStorage.Auto = 'false';
		localStorage.Tab = Number(localStorage.Tab) + 1;
		localStorage.Force = 'true';
		window.location.href = '../wp-admin/post-new.php?bot=true';
		return;
		//Show_Tab(Number(localStorage.Tab));
	} else {					
		//alert('trigger auto click');
		$('.feeds-wrapper .item a:last').trigger('click');					
	}
}

function Fetch_Link() {


	if (Auto_Post == true) {
		$(this).parents('.item').remove();
		$(this).remove();
	}

	$('.process-bar').css('display','inline');
	Pbar_Update('Fetching post ... ');
	Pbar_Show();
	
	Scroll_To('#title');
	$('a#content-html').trigger('click');// `switch to HTML mode
	
	// `update post title
	$('#title').val(Title);
	$('.wp-editor-area').trigger('focus');
	$('.wp-editor-area').val('Something is missing here!');
	
	Image_Total = 0;
	Image_Index = 0;						
	
	// $.ajax({
		// url: home_url + '/get',
		// type: 'POST',
		// data: 'url='+UTF8_To_Ascii(Link),
		// success: function(data) {  
			// if (Fetch_Error(data, Link)) {
				// Pbar_Hide();				
				// if (localStorage.Auto == 'true') {
					// Feed_Trigger_Click();
				// } else {
					// alert('Error:'+data);
					// $(FP).html(data);
				// }
			// } else {
				// first_feed_process( data );
			// }
		// }
	// });		
	$.post(home_url + '/get', {
		url:UTF8_To_Ascii(Link),
		force:'true'
	}, 
	function(data){
		if (Fetch_Error(data, Link)) {
			Pbar_Hide();				
			debug('Fetch_Link Error');
			error('Fetch_Link()');
		} else {
			first_feed_process( data );
		}
	});
	
}

/* `prevent fetch some special files base on its title */
function This_Not_Fetch() {
	for (var i = 0; i < Not_Fetch.length; i += 2) {
		if (Link.indexOf(Not_Fetch[i]) != -1)
			break;
	}
	if (i < Not_Fetch.length) {
		var keys = [];
		keys = Not_Fetch[i+1].split(',');
		for (var j = 0; j < keys.length; j++) {
			if (Title.indexOf(keys[j]) != -1) {
				debug('Because "'+Title+'" contains "'+keys[j]+'" of site "'+Not_Fetch[i]+'", so we not fetch!');
				return true;
			}
		}
	}
	
	return false;
}

function is_duplicate_title(title){
	var a = title.split(' ');
	var b = localStorage.Titles.split(',');
	for (var i = 0; i < a.length - 5; i++) {
		var str = a[i]+' '+a[i+1]+' '+a[i+2]+' '+a[i+3]+' '+a[i+4];
		for (var j = 0; j < b.length; j++) {
			if (b[j].indexOf(str) != -1) {
				debug('Duplicated title');
				return true;
			}
		}
	}
	debug('Good title');
	return false;
}
////Load post when click a link in feed
$('.feeds-wrapper a').live('click', function(){
	debug('###########New click');
	// `get link and title
	Image_Backup = '';
	Link = $(this).attr('path');
	Title = $(this).text();
	debug('Link = ' + Link);
	
	if (Title.indexOf('...') != -1 && $(this).attr('title') != null) {
		temp = $(this).attr('title');
		if (temp.length > Title.length) {
			Title = temp;
		}
	}
	
	$(this).parents('.item').children('img:last').each(function () {
		debug('May be has backup image');
		src = $(this).attr('src');
		if (src != null) {
			Image_Backup = src;
			debug('Backed up: ' + Image_Backup);
		}
	});
	$(this).parents('.item').remove();
	$(this).remove();
		
	/* `save link and title to prevent DOUPLICATE CONTENT 
	###################################################### */
	if (localStorage.Links.indexOf(Link) == -1) {
		localStorage.Links = localStorage.Links + ',' + Link;
	} else {	
		debug('The link is already in list');
		if (localStorage.Auto == 'true') {
			Feed_Trigger_Click();
			return;
		}
	}
	
	if ((localStorage.Titles.indexOf(Title) == -1) && (is_duplicate_title(Title) == false)) {
		localStorage.Titles = localStorage.Titles + ',' + Title;
	} else {
		debug('The title is already in list');
		if (localStorage.Auto == 'true') {
			Feed_Trigger_Click();
			return;
		}
		
	}
	
	if (localStorage.Auto == 'true' && This_Not_Fetch()) {
		error('Found bad fetch');
		return;
	}
	
	Fetch_Link();			
});


////Replace all image src if missing in feed list
function Replace_Feed_Thumb() {
    var host = Get_Host(Feed_List[Feed_Index]);    
    $(FP + ' img').each(function(){
        src = $(this).attr('src');           
        
        if (typeof(src)!='undefined') {
            if (src.indexOf('http') == -1) {                
                src = 'http://' + host + src;
                $(this).attr('src', src);                             
            }
        }
    });
    
    
}


function Replace_Feed_Link() {
    var host = Get_Host(Feed_List[Feed_Index]); 
    $(FP +' a').each(function(){
        href= $(this).attr('href');
        if (typeof(href)!='undefined') {
            if (href.indexOf('http') == -1) {                
                href = 'http://' + host + href;
            }
			$(this).attr('href', '#change');   
			$(this).removeAttr('target');
			
			/* `add path */
			$(this).attr('path', href);
        } else {
			$(this).remove();
		}                    
    });  
}

function Clear_Image_Links() {
	$(FP + ' img').each(function () {
        if (typeof($(this).parents('a') != 'undefined')) {
            src = $(this).attr('src');
            if (typeof(src) != 'undefined') {
                ////Prevent remove in some cases
                ////############################
                // if (src.indexOf('Photo.gif') != -1 || src.indexOf('Video.gif') != -1) {return;}////gamethu.vnexpress.net
				
				////vnexpress.net
                if (src.indexOf('Images/photo.gif') != -1 || src.indexOf('Images/video.gif') != -1) {return;}
				
				////kienthuc.net.vn
                if (src.indexOf('/Themes/Images/icon/video.png') != -1 || src.indexOf('/Themes/Images/icon/image.png') != -1) {return;}
				
				////dantri.com.vn
                if (src.indexOf('photo2.png') != -1 || src.indexOf('video2.png') != -1) {return;}
                                
                $('<img src="'+src+'"/>').insertAfter($(this).parents('a'));                
            }
            $(this).parents('a').remove();
        }
    });
}

////Return HTML for a feed link in list (category)
function Feed_Add(data) {
    var title = Get_Str_Between_Tag(data, 'title');

    ////Common body get
    var body = Get_Str_Between_Tag(data, 'body');

    ////Common remove
    var tagopen = '<script';
    var tagclose = '</script>';
    while (body.indexOf(tagopen) != -1) {
        body = Remove_Str_Between_Keys(body, tagopen, tagclose);
    }   
    //alert(1);
    var tagopen = '<Script';
    var tagclose = '</Script>';
    while (body.indexOf(tagopen) != -1) {
        body = Remove_Str_Between_Keys(body, tagopen, tagclose);
    }   
    //alert(2);
    var tagopen = '<style';
    var tagclose = '</style>';
    while (body.indexOf(tagopen) != -1) {
        body = Remove_Str_Between_Keys(body, tagopen, tagclose);
    }   
    //alert(3);
    var tagopen = '<!--';
    var tagclose = '-->';
    while (body.indexOf(tagopen) != -1) {
        body = Remove_Str_Between_Keys(body, tagopen, tagclose);
    }   
    //alert(4);
    var tagopen = '<noscript';
    var tagclose = '</noscript>';
    while (body.indexOf(tagopen) != -1) {
        body = Remove_Str_Between_Keys(body, tagopen, tagclose);
    }   
    //alert(5);


    
    /*
    body = body.replace(/&/gi,'&amp;');
    body = body.replace(/</gi,'&lt;');
    body = body.replace(/>/gi,'&gt;')
    */
    /* `common process */
    //alert(body);
    $(FP).html(body);
    Replace_Feed_Thumb();
    Replace_Feed_Link();
    Clear_Image_Links();
    
	////Fetch category
	//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	
	////kienthuc.net.vn cate
    ////####################
    if (Feed_List[Feed_Index].indexOf('kienthuc.net.vn') != -1) {
		$(FP + ' .content_ref').remove();
		body = ''
		$(FP + ' #listpage .box-wiget-content').first().each(function () {
			body += '<div class="item">'+$(this).html()+'</div>';
		});
		
		$(FP + ' #listpage .spec-news-col2 li').each(function () {
			body += '<div class="item">'+$(this).html()+'</div>';
		});
		
		$(FP + ' #listpage .list-news li').each(function () {
			body += '<div class="item">'+$(this).html()+'</div>';
		});
		
    } 
    else
	
	////tiin.vn cate
    ////####################
    if (Feed_List[Feed_Index].indexOf('tiin.vn') != -1) {
		
		$(FP + ' .ul-lnk-other-primary').remove();
		body = ''
		$(FP + ' #primary-cate-news').each(function () {
			body += '<div class="item">'+$(this).html()+'</div>';
		});
		
		$(FP + ' #cat-news-list-container .cl-row').each(function () {
			body += '<div class="item">'+$(this).html()+'</div>';
		});
		
    } 
    else
	
	////baodatviet.vn cate
    ////####################
    if (Feed_List[Feed_Index].indexOf('baodatviet.vn') != -1) {
		
		$(FP + ' .date').remove();
		body = '<div class="item">';
		$(FP + ' .focus_title:first').each(function () {
			body += $(this).html();
		});
		$(FP + ' .focus_sapo:first').each(function () {
			body += $(this).html();
		});
		
		body += '</div>';
		
        
		$(FP + ' .content_item').each(function () {
			body += '<div class="item">'+$(this).html()+'</div>';
		});
    } 
    else
	
	////tinmoi.vn cate
    ////####################
    if (Feed_List[Feed_Index].indexOf('tinmoi.vn') != -1) {
		$(FP + ' div').each(function () {
			divid = $(this).attr('id');
			if (typeof(divid) != 'undefined' && divid != null) {
				if (divid.indexOf('div-gpt-ad') != -1) {
					$(this).parents('li').remove();
				}
			}
		});
	
		body = '';
        
		$(FP + ' ul.list-post li').each(function () {
			body += '<div class="item">'+$(this).html()+'</div>';
		});
    } 
    else
	
	////http://vntimes.com.vn cate
    ////####################
    if (Feed_List[Feed_Index].indexOf('vntimes.com.vn') != -1) {
		
		body = '';
        
		$(FP + ' .news-list .news-item').each(function () {
			body += '<div class="item">'+$(this).html()+'</div>';
		});
    } 
    else
	
	////archi.vn cate
    ////####################
    if (Feed_List[Feed_Index].indexOf('archi.vn') != -1) {
		$(FP + ' .highlightprojects-other').remove();
		$(FP +' .highlightnews-wrap').remove();
		
		body = '';
        
		$(FP + ' .panel-highlightnews1').each(function () {
			body += '<div class="item">'+$(this).html()+'</div>';
		});
        $(FP + ' .foldercatalog .last-border').each(function () {
			body += '<div class="item">'+$(this).html()+'</div>';
		});
        
    } 
    else
	
	////batdongsan.com.vn cate
    ////####################
    if (Feed_List[Feed_Index].indexOf('batdongsan.com.vn') != -1) {
		body = '';
        
		$(FP + ' .item-cate-first').each(function () {
			body += '<div class="item">'+$(this).html()+'</div>';
		});
        $(FP + ' .item-cate').each(function () {
			body += '<div class="item">'+$(this).html()+'</div>';
		});
        
    } 
    else
	
	////DOTHI.NET cate
    ////####################
    if (Feed_List[Feed_Index].indexOf('dothi.net') != -1) {
        $(FP + ' .titleListGroup').remove();
        $(FP + ' .tagsSearch2.clearfix').remove();
        $(FP + ' .bdrBtom .padT4.clor9').remove();
        $(FP + ' #boxGroupListNew .bdrBtom .fLeft.clor9.f-11').remove();
        $(FP + ' #boxGroupListNew .titleDthi.bold.f-14').remove();
        $(FP + ' #boxGroupListNew .lisDthi').remove();
        $(FP + ' #boxGroupListNew .padT10').remove();
        
        body = '<div class="item">'+$(FP + ' .padT15.padB15.padR12').html()+'</div>';
		$(FP + ' .listGroupNews li').each(function () {
			body += '<div class="item">'+$(this).html()+'</div>';
		});
        
    } 
    else
	
	
	////BONGDAPLUS.VN cate
    ////####################
    if (Feed_List[Feed_Index].indexOf('bongdaplus.vn') != -1) {
        $(FP + ' .related').remove();
        $(FP + ' .ads').remove();
        $(FP + ' .storyinfo').remove();
        
        body = '';
        $(FP + ' .mainbox .story').each(function () {
            body += '<div class="item">'+$(this).html()+'</div>';            
        });
		$(FP + ' .newest .story').each(function () {
            body += '<div class="item">'+$(this).html()+'</div>';            
        });
		$(FP + ' .cate-list .story').each(function () {
            body += '<div class="item">'+$(this).html()+'</div>';            
        });        
    } 
    else
	
	////KENH14.VN cate
    ////####################
    if (Feed_List[Feed_Index].indexOf('kenh14.vn') != -1) {
        $(FP + ' .readmore').remove();
        $(FP + ' .read_more_news_hot_eva').remove();
        $(FP + ' .chuThichAnh').remove();
        $(FP + ' .text-content a').remove();
		$(FP + ' .div_brief_news a').remove();
        body = '';
        $(FP + ' #mainfeature').each(function () {
            body += '<div class="item">'+$(this).html()+'</div>';            
        });
		$(FP + ' #otherfeature .item').each(function () {
            body += '<div class="item">'+$(this).html()+'</div>';            
        });
        $(FP + ' .listnews .item').each(function () {
            body += '<div class="item">'+$(this).html()+'</div>';            
        });				
    } 
    else
	
	
	////EVA.VN cate
    ////####################
    if (Feed_List[Feed_Index].indexOf('eva.vn') != -1) {
        $(FP + ' .box-note').remove();
        $(FP + ' .tieuDePhu').remove();
        $(FP + ' .read_more_news_hot_eva').remove();
        $(FP + ' .chuThichAnh').remove();
        $(FP + ' .text-content a').remove();
		$(FP + ' .div_brief_news a').remove();
        body = '';
        $(FP + ' .baiNoiBat-c').each(function () {
            body += '<div class="item">'+$(this).html()+'</div>';            
        });
		$(FP + ' .boxDonItem').each(function () {
            body += '<div class="item">'+$(this).html()+'</div>';            
        });                        
    } 
    else
	
	
	////IONE.VNEXPRESS.NET cate
    ////####################
    if (Feed_List[Feed_Index].indexOf('ione.vnexpress.net') != -1) {
        $(FP + ' .highlight2').remove();
        body = '';
        $(FP + ' .showbiz-hot').each(function () {
            body += '<div class="item">'+$(this).html()+'</div>';            
        });
		$(FP + ' .showbiz-left .box-life').each(function () {
            body += '<div class="item">'+$(this).html()+'</div>';            
        });                
    } 
    else
	
	
	////DANTRI.COM.VN cate
    ////####################
    if (Feed_List[Feed_Index].indexOf('dantri.com.vn') != -1) {
        $(FP + ' .icon-detail').remove();
        $(FP + ' .subtitle').remove();
        $(FP + ' .fl .mt3 .fon5 a').remove();
        body = '';
        $(FP + ' .fl .mt3').each(function () {
            body += '<div class="item">'+$(this).html()+'</div>';            
        });                
    } 
    else
	
	////VOV.VN cate
    ////####################
    if (Feed_List[Feed_Index].indexOf('vov.vn') != -1) {
        $(FP + ' .highlight').remove();
        $(FP + ' .relate').remove();
		//$(FP + ' .story:first').remove();////Prevent duplicate content
        body = '';
        $(FP + ' .story').each(function () {
            body += '<div class="item">'+$(this).html()+'</div>';            
        });               
    } 
    else
	
	
    ////NEWS.ZING.VN cate
    ////####################
    if (Feed_List[Feed_Index].indexOf('news.zing.vn') != -1) {
        $(FP + ' p.tag').remove();
        body = '';
        $(FP + ' .cate_featured li').each(function () {
            body += '<div class="item">'+$(this).html()+'</div>';            
        });
        $(FP + ' #articles_day_data #main_list li').each(function () {
            body += '<div class="item">'+$(this).html()+'</div>';            
        });        
    } 
    else
    ////GAMETHU.VNEXPRESS.NET cate
    ////####################
    if (Feed_List[Feed_Index].indexOf('gamethu.vnexpress.net') != -1) {
        $(FP + ' .LargerBoxDown_left').remove();
        body = '';
        $(FP + ' .LargerBoxDown').each(function () {
            body += '<div class="item">'+$(this).html()+'</div>';            
        });
        $(FP + ' .Ul_OtherNewsSubPage li').each(function () {
            body += '<div class="item">'+$(this).html()+'</div>';            
        });        
    } 
    else
    ////Specific remove
    ////SOHOA.vnexpress.net cate
    ////####################
    if (Feed_List[Feed_Index].indexOf('sohoa.vnexpress.net') != -1) {
        /* `remove un-useful elements */      
        $(FP + ' .pHomen .trend-suoc').remove();
        $(FP + ' .pHomen .spanTren').remove();
        $(FP + ' .pHomen .share-link').remove();
        
        body = '';
        $(FP + ' .topVote').each(function () {
            body += '<div class="item">'+$(this).html() + '</div>';
        });
        $(FP + ' .homen-left .liListHome').each(function () {
            body += '<div class="item">'+$(this).html()+'</div>';
        });            
    } else
    ////Specific remove
    ////VNEXPRESS.NET cate
    ////####################
    if (Feed_List[Feed_Index].indexOf('vnexpress.net') != -1) {
        /* `remove un-useful elements */      
        $(FP + ' .folder-header').remove();
        $(FP + ' .folder-bottom2').remove();       
        $(FP + ' .Lead').remove();         
        $(FP + ' .continue').remove();         
        $(FP + ' table').remove();         
        
        $(FP + ' .folder-top').addClass('folder-news');         
		$(FP + ' .folder-news:last').remove();
		$(FP + ' .folder-news:last').remove();
		
		body = '';
		$(FP + ' .folder-news').each(function () {
			body += '<div class="item">' + $(this).html() + '</div>';
		});
		
        
    
    } else 
    ////24H.COM.VN cate
    ////####################
    if (Feed_List[Feed_Index].indexOf('24h.com.vn') != -1) {
        $(FP + ' .divXemTiep').remove();
        $(FP + ' #news_nextnews2').remove();
        $(FP + ' #next_news').remove();
        $(FP + ' #relate_cat').remove();
        $(FP + ' .baiviet-bailienquan').remove();
        $(FP + ' .boxDoi-sub-tab').remove();
        //$(FP + ' .boxDoi-sub-c').last().remove();
        $(FP + ' .listNews').each(function () {
            $(this).parents('.boxDoi-sub-c').remove();
            $(this).remove();
        });
        $(FP + ' .baiviet-TopContent .text-conent').remove();
        body = '';
        $(FP + ' .green-box-content').each(function () {
            body += '<div class="item">'+$(this).html() + '</div>';
        });
        $(FP + ' .boxDonItem').each(function () {
            body += '<div class="item">'+$(this).html()+'</div>';
        });                    
    } else 
    ////VTC.VN cate
    ////####################
    if (Feed_List[Feed_Index].indexOf('vtc.vn') != -1) {
        $(FP + ' .p2_listphu').remove();
        $(FP + ' .p2_listchuyenmucphu').remove();
        $(FP + ' .ke').remove();
        $(FP + ' .clear').remove();
		/*
        $(FP + ' .p2_listchuyenmucphu a').each(function () {
            id = $(this).attr('id');
            if (id.indexOf('hlDateCate') != -1) {
                $('<span class="date">'+$(this).text()+'</span>').insertAfter($(this).parents('.p2_listchuyenmucphu'));
                $(this).parents('.p2_listchuyenmucphu').remove();
            }
        });
        */
        $('span.Summary_home').each(function () {
            text = $(this).text();
            text = Get_Str_Between_Tag(text, 'a');
            $(this).text(text);
        });
        
        
        
        
        //body = $(FP + '#ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_pnlTopNews').html();
        //$(FP).html(body);
        body = '';
        $(FP + ' .truyenhinh').each(function () {
            body += '<div class="item">'+$(this).html() + '</div>';
        });
        $(FP + ' .p2_tinchinh').each(function () {
            body += '<div class="item">'+$(this).html()+'</div>';
        });                 
    }
    
    else 
    ////VIETNAMNET.VN cate
    ////####################
    if (Feed_List[Feed_Index].indexOf('vietnamnet.vn') != -1) {
        body = '';
        $(FP + ' .cateFistPost').each(function () {
            body += '<div class="item">'+$(this).html() + '</div>';
        });
        $(FP + ' .focusNewBoxList-item').each(function () {
            body += '<div class="item">'+$(this).html()+'</div>';
        });     
        $(FP + ' .columnsPageLeft > div.margin-bottom-10').each(function () {
            body += '<div class="item">'+$(this).html() + '</div>';
        });        
        
        
    }
    else 
    ////NGOISAO.NET cate
    ////####################
    if (Feed_List[Feed_Index].indexOf('ngoisao.net') != -1) {
        body = '';
        $(FP + ' .tnht div.news').each(function () {
            body += '<div class="item">'+$(this).html() + '</div>';
        });
        $(FP + ' div.newso li').each(function () {
            body += '<div class="item">'+$(this).html()+'</div>';
        });     
        $(FP + ' ul.news li').each(function () {
            body += '<div class="item">'+$(this).html() + '</div>';
        });        
       
        
    }
    else 
    ////2SAO.VN cate
    ////####################
    if (Feed_List[Feed_Index].indexOf('2sao.vn') != -1) {
        body = '';
        $(FP + ' #nbm').each(function () {
            body += '<div class="item">'+$(this).html() + '</div>';
        });
        $(FP + ' #nbm_1').each(function () {
            body += '<div class="item">'+$(this).html()+'</div>';
        });     
        $(FP + ' #nbm_2').each(function () {
            body += '<div class="item">'+$(this).html() + '</div>';
        });  
        $(FP + ' #nbm_3').each(function () {
            body += '<div class="item">'+$(this).html() + '</div>';
        }); 
        $(FP + ' #listNews div div').each(function () {
            body += '<div class="item">'+$(this).html() + '</div>';
        }); 
        
       
    }
    else 
    ////TUOITRE.VN cate
    ////####################
    if (Feed_List[Feed_Index].indexOf('tuoitre.vn') != -1) {
		$(FP + ' a').each(function () {
			text = $(this).text();
			if (text == 'Xem tiếp »') $(this).remove();
		});
	
        body = '';
        $(FP + ' p').each(function () {
            style = $(this).attr('style');
            if (typeof(style) != 'undefined') {
                if (style.indexOf('margin:0px;padding:8px;overflow:hidden;float:left;background-color:#076aa9;') != -1) {
                    body += '<div class="item">'+$(this).html()+'</div>';
                }
            }
        });
        $(FP + ' div').each(function () {
            style = $(this).attr('style');
            if (typeof(style) != 'undefined') {
                if (style.indexOf('width: 672px; clear: both; overflow: hidden; margin-top: 5px; margin-bottom: 5px;') != -1) {
                    body += '<div class="item">'+$(this).html()+'</div>';
                }
            }
        });                
    }
    Cur_HTML += '<h2 class="feeds-title">'+title+'</h2>';
    Cur_HTML += '<div class="feeds">';
    Cur_HTML += body;
    Cur_HTML += '</div><div class="clear"></div>';
    
          
}



////Load all feeds for a tab
function Feed_Load() {
	//alert('Your are in feed');
    // $.ajax({
        // url: home_url + '/get',
        // type: 'POST',
        // data: 'url='+UTF8_To_Ascii(Feed_List[Feed_Index]) + localStorage.Force,
        // success: function(data) {
			
        // }
    // });
	$.post(home_url + '/get', {
		url:UTF8_To_Ascii(Feed_List[Feed_Index]),
		force:localStorage.Force
	}, 
	function(data){
		localStorage.Force = 'false';
		if (Fetch_Error(data, UTF8_To_Ascii(Feed_List[Feed_Index]))) {
			Feed_Load();
			return;// `retry if have error
		}
		Feed_Add( data );
		$('.feeds-wrapper').html(Cur_HTML);
		
		Feed_Index++;
		//alert(Feed_Index);
		if (Feed_Index == Feed_Total) {                                          
			////Enable Auto Post here
			// `##########################
			if (localStorage.Auto == 'true') {
				// `clean up links if support HTML 5
				$('.feeds-wrapper .item a').each(function () {
					text = $(this).html();
					//alert('temp = ' + temp);
					path = $(this).attr('path');
					
					if (localStorage.Links.indexOf(path) != -1 || localStorage.Titles.indexOf(text) != -1) {
						$(this).parents('.item').remove();
						$(this).remove();
					}
				});						
				Feed_Trigger_Click();
			}
			
		} else {
			//alert('Feed load continue');
			Feed_Load();
		}
	});
	
}

function Show_Tab(tab_id) {
    ////Reset data
    Cur_HTML = '';
    Tab_HTML = '';
    Feed_Index = 0;
	localStorage.Tab = tab_id;
	if (Number(localStorage.Tab) >= Max_Tab) {
		localStorage.Tab = 0;
	}
	Cur_Tab = Number(localStorage.Tab);
	
    ////Get feed list
    Feed_List = FL[Number(localStorage.Tab) * 2 + 1].split(',');
    Feed_Total = Feed_List.length;
	
    ////Get tab list html and show it
    for (var i = 0; i < Max_Tab; i++) {
        Tab_HTML += '<h2 class="feeds-title">';
        if (i == Number(localStorage.Tab)) {
            Tab_HTML += FL[i * 2];
        } else {
            Tab_HTML += '<a href="#" tab_id="'+i+'">'+ FL[i * 2] + '</a>';
        }
        Tab_HTML += '</h2>';
    }
    Tab_HTML += '<div class="clear"></div>';
    $('.feed-channels').html(Tab_HTML);
    
    ////Get feeds in Feed_List and display them
    $('.feeds-wrapper').html('Loading ... ');
    Feed_Load();
}

////Load feeds from a tab when clicked
$('.feed-channels a').live('click', function(){
    var tab_id = Number($(this).attr('tab_id'));
	localStorage.Force = 'true';
    Show_Tab(tab_id);
});



$('.auto-post').click(function () {
	if (localStorage.Auto == 'false') localStorage.Auto = 'true';
	else localStorage.Auto = 'false';
	$('.auto-post').html('Auto post = '+localStorage.Auto);
});

// `clean up storage
if (localStorage.Links.length >= 1000000) {
	localStorage.Links = Str_Get_After_Key(localStorage.Links, ',');
}
if (localStorage.Titles.length >= 1000000) {
	localStorage.Titles = Str_Get_After_Key(localStorage.Titles, ',');
}
if (localStorage.Errors.length >= 500000) {
	localStorage.Errors = Str_Get_After_Key(localStorage.Errors, ',');
}

$('#fetch_it').click(function () {
	Link = $('#custom_fetch').val();
	Title = 'Custom Fetch for Debug';
	Fetch_Link();
});



$(document).ready(function () {
	// alert(UTF8_To_Ascii('http://vov.vn/Uploaded/quangtrung/2012_11_06/ANH VIET THANG.jpg'));
	
	// $.ajax({
			// url: home_url + '/get',
			// type: 'POST',
			// data: 'url=http://vov.vn/Uploaded/quangtrung/2012_11_06/real%2520dort.jpg&force=true',
			// success: function(data) {							
				// alert(data);
			// }
		// }); 
		// $.post(home_url + '/get', {
			// url:'http://vov.vn/Uploaded/quangtrung/2012_11_06/real%2520dort.jpg',
			// force:'true'
		// }, 
		// function(data){
			// debug(data);
		// });
	// return;
	uri = window.location.href;
	
	$('.auto-post').html('Auto post = '+localStorage.Auto);
	
	//alert('fetch_force = '+Fetch_Force);
	
	if (uri.indexOf('&action=edit') != -1) {
		if (localStorage.Auto == 'true') {
			if (uri.indexOf('bot=false') == -1) {
				window.location.href = home_url + '/wp-admin/post-new.php?bot=true';
			}
			else {
				$('.feed-bot').remove();
				return;
			}
		}
		else {
			$('.feed-bot').remove();
		}
	} else {
		// `always check bot option to load
		if (uri.indexOf('bot=true') == -1) {
			$('.feed-bot').remove();
			return;
		}
	}
	
	Show_Tab(Number(localStorage.Tab));
    
});

